package o;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.ActivityChooserView.ActivityChooserViewAdapter;
import com.google.android.exoplayer2.upstream.cache.Cache.CacheException;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.TreeSet;

final class amc {
    private amj ˊ = amj.ˎ;
    public final String ˋ;
    private boolean ˎ;
    private final TreeSet<aml> ˏ = new TreeSet();
    public final int ॱ;

    public static amc ˎ(int i, DataInputStream dataInputStream) throws IOException {
        amc o_amc = new amc(dataInputStream.readInt(), dataInputStream.readUTF());
        if (i < 2) {
            long readLong = dataInputStream.readLong();
            ami o_ami = new ami();
            amg.ˋ(o_ami, readLong);
            o_amc.ˎ(o_ami);
        } else {
            o_amc.ˊ = amj.ˎ(dataInputStream);
        }
        return o_amc;
    }

    public amc(int i, String str) {
        this.ॱ = i;
        this.ˋ = str;
    }

    public void ˊ(DataOutputStream dataOutputStream) throws IOException {
        dataOutputStream.writeInt(this.ॱ);
        dataOutputStream.writeUTF(this.ˋ);
        this.ˊ.ˏ(dataOutputStream);
    }

    public amh ˏ() {
        return this.ˊ;
    }

    public boolean ˎ(ami o_ami) {
        amj o_amj = this.ˊ;
        this.ˊ = this.ˊ.ˊ(o_ami);
        return !this.ˊ.equals(o_amj);
    }

    public boolean ˎ() {
        return this.ˎ;
    }

    public void ˏ(boolean z) {
        this.ˎ = z;
    }

    public void ˋ(aml o_aml) {
        this.ˏ.add(o_aml);
    }

    public TreeSet<aml> ˋ() {
        return this.ˏ;
    }

    public aml ˋ(long j) {
        aml ˎ = aml.ˎ(this.ˋ, j);
        aml o_aml = (aml) this.ˏ.floor(ˎ);
        if (o_aml != null && o_aml.ॱ + o_aml.ˋ > j) {
            return o_aml;
        }
        o_aml = (aml) this.ˏ.ceiling(ˎ);
        if (o_aml == null) {
            return aml.ˋ(this.ˋ, j);
        }
        return aml.ॱ(this.ˋ, j, o_aml.ॱ - j);
    }

    public long ˏ(long j, long j2) {
        aml ˋ = ˋ(j);
        long j3;
        if (ˋ.ˊ()) {
            if (ˋ.ˋ()) {
                j3 = Long.MAX_VALUE;
            } else {
                j3 = ˋ.ˋ;
            }
            return -Math.min(j3, j2);
        }
        long j4;
        long j5 = j + j2;
        j3 = ˋ.ॱ + ˋ.ˋ;
        if (j3 < j5) {
            j4 = j3;
            for (aml o_aml : this.ˏ.tailSet(ˋ, false)) {
                if (o_aml.ॱ > j4) {
                    break;
                }
                j3 = Math.max(j4, o_aml.ˋ + o_aml.ॱ);
                if (j3 >= j5) {
                    j4 = j3;
                    break;
                }
                j4 = j3;
            }
        } else {
            j4 = j3;
        }
        return Math.min(j4 - j, j2);
    }

    public aml ॱ(aml o_aml) throws CacheException {
        aml ˊ = o_aml.ˊ(this.ॱ);
        if (o_aml.ˊ.renameTo(ˊ.ˊ)) {
            amm.ˏ(this.ˏ.remove(o_aml));
            this.ˏ.add(ˊ);
            return ˊ;
        }
        throw new CacheException("Renaming of " + o_aml.ˊ + " to " + ˊ.ˊ + " failed.");
    }

    public boolean ॱ() {
        return this.ˏ.isEmpty();
    }

    public boolean ˏ(amd o_amd) {
        if (!this.ˏ.remove(o_amd)) {
            return false;
        }
        o_amd.ˊ.delete();
        return true;
    }

    public int ˏ(int i) {
        int hashCode = (this.ॱ * 31) + this.ˋ.hashCode();
        if (i >= 2) {
            return (hashCode * 31) + this.ˊ.hashCode();
        }
        long ˊ = amg.ˊ(this.ˊ);
        return (hashCode * 31) + ((int) (ˊ ^ (ˊ >>> 32)));
    }

    public int hashCode() {
        return (ˏ((int) ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED) * 31) + this.ˏ.hashCode();
    }

    public boolean equals(@Nullable Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        amc o_amc = (amc) obj;
        if (this.ॱ == o_amc.ॱ && this.ˋ.equals(o_amc.ˋ) && this.ˏ.equals(o_amc.ˏ) && this.ˊ.equals(o_amc.ˊ)) {
            return true;
        }
        return false;
    }
}
